Return to doc.sitecore.com

4.  Advanced Code
Prev
Sitecore V4 Sitecore V5
External data import
Data Providers, Child providers Data providers
Linking Sitecore data
Linked database and virtual nodes Proxy / Shadow Items
Sitecore extensibility
Server Events Event system
Client Events Sheer UI message system
Http request lifecycle (hardcoded) ‘httpRequestBegin’ pipeline
- Pipelines for core system actions
- User interface pipelines
Template Controls Custom Field Types
Security
Hardcoded security engine Security Domain
- Virtual users

4.1.  Importing External Data

Whether you need to import an Item along with its children or children only from outside of Sitecore, you should use data providers in Sitecore V5. Data providers replace both child providers and data providers in Sitecore V4, and offer more flexibility.  

If you have relied on web index in Sitecore V4 to persist Item IDs, you should use IDTable mechanism in Sitecore V5.  

Supplementary reading:

4.2.  Linking Sitecore Data

With Sitecore V5 you can use proxy/shadow items to make Sitecore items appear in multiple places at the same time, both inside same database and between multiple databases. No custom code required.  

Read more about proxy Items here:

4.3.  Handling System Events

Instead of various Sitecore V4 handlers (like ItemEventHandler, MediaHandler, Publishing Handler and so on), Sitecore V5 offers unified event model.   

Sitecore V5 events also address some of the shortcomings that Sitecore V4 handlers had.  

To port your specific handler to Sitecore V5 you need to

Example:  

Say, you had an Item event handler that replaces all ‘*’ symbols in an Item’s name (taken from Sitecore V4 server events article):  

public class CustomItemHandler : IItemEventHandler

{
  
//Replaces the "*" symbols on gaps
   void IItemEventHandler.HandleSaved(IMasterItem itm, NameValueCollection configSettings)
   {
      
string szTitle = itm.GetFieldValue("Title");
      itm.GetLatestVersion().SetFieldValue(
"Title", szTitle.Replace("*"," "));
   }
}

and the handler is registered in web.config in the following way:  

   <eventHandlers>
     ...
      <items>
        …
        <handler mode="on" assembly="CustomItemHandler" type="CustomItemHandler" CustomNodeTitle="New Item: "/>

      </items>

      ...

    </eventHandlers>

4.4.  Sitecore V5 Event

We will achieve the same result with Sitecore V5 event:

  1. HandleSaved method of IItemEventHandler gets invoked on each item save in Sitecore V4. It corresponds to the “item:saved” event of Sitecore V5.
     
  2. “item:saved” event provides exactly the argument we need, that is Item that was saved. We will modify our handler method accordingly: 
// no need to inherit from the base class or implement any interfaces
public class CustomItemHandler
{
  
// using common event handler method signature
   public void OnItemSaved(object sender, EventArgs args)
   {

      
// extracting the event parameter – in this case item that was saved

       Item saved
= Event.ExtractParameter(args, 0) as Item;

// Same logic we had in Sitecore V4, updated to use Sitecore V5 API

       using (new EditContext(saved))

       {

            saved[“Title”] = saved[“Title”].Replace(“*”, “”);

       }

   }

}

then we subscribe our event handler to “item:saved” event in web.config  

<events>

...

   <event name="item:saved">

      <!-- notice the change between how type is described in V4 and V5 -->
      <handler type="CustomItemHandler, CustomItemHandler" method="OnItemSaved"/>

   </event>

    ...

</events>

All other events are handled in the same way. If you have PublishHandler, you will need to subsribe to one of the “publish:begin”, “publish:end” or “publish:fail” events and use the provided Publisher to access the event data.

Supplementary reading:

4.5.  Handling Client Events

Similar to server events, in Sitecore V5 client events evolved into a unified message system. Those who used messages in Sitecore V4 client script will feel familiar with this feature. Messages can be used both at client and server side in Sitecore V5 and are often used to communicate between two sides.   

Message handlers are set up in web.config similar to the events:

      <messages>
        […]
        
<message name="system:logout" type="Sitecore.Web.UI.Framework.Security,Sitecore.Kernel" method="OnLogout"/>
        
<message name="system:publish" type="Sitecore.Web.UI.Framework.Items,Sitecore.Kernel" method="OnPublish"/>
        
<message name="system:preview" type="Sitecore.Web.UI.Framework.Items,Sitecore.Kernel" method="OnPreview"/>
        
<message name="system:rebuildlinkdatabase" type="Sitecore.Web.UI.Framework.Dialogs,Sitecore.Kernel" method="OnRebuildLinkDatabase"/>

        <message name="dbupgrade:run" type="Sitecore.Modules.Upgrade.UI.MessageHandler,Sitecore.Upgrade" method="Run"/>

      […]

      </messages>

You can hook into the chain for any of the existing messages and also expose your own ones.  

4.6.  Replacing Webcontrols

This section contains information about replacing Sitecore 4 WebControls with equivalent Sitecore 5 Controls.

4.6.1.  generator and iteminfo

When performing a migration from version 4 to version 5, replace generator and sc_iteminfo webcontrols shown below

  <sc:generator runat="server" id="Generator1" />

  <sc:iteminfo runat="server" id="Iteminfo1" />

with the following meta tags:

  <meta name="generator" content="<%# Sitecore.Configuration.About.VersionInformation() %>" >

  <meta name="sc_iteminfo" content="path=<%# Sitecore.Context.Item.Paths.Path.ToLower() %>; id=<%# Sitecore.Context.Item.ID.ToString() %>" > 


Prev